import {ref} from "vue";
import axios from "@/utils/axios";
import {message} from "ant-design-vue";

class Moisture{
    id: number | undefined = -1
    mpId: number | undefined
    mpUuid: string | undefined
    formulaId: string | undefined

    gl1: number | undefined
    gl2: number | undefined
    gl3: number | undefined
    gl4: number | undefined
    gl5: number | undefined
    gl6: number | undefined

    waterPlan: number | undefined
    createDate: string | undefined
}

export default ()=>{
    const moistureChecked = ref(new Moisture())

    // 获根据拌合站id及指定日期获取含水率
    const getMoistureByMpIdAndDate = (moisture:Moisture)=>{
        axios
            .post("/mix/formal/getMoistureByMpIdAndDate",moisture)
            .then((res:any) => {
                if(res.data != null) Object.assign(moistureChecked.value, res.data);
                if(res.data == null) moistureChecked.value = moisture;
                moistureChecked.value.mpUuid = "";
            });
    }

    // 更新今日含水率
    const updateMoisture = ()=>{
        axios
            .post("/mix/formal/updateMoisture",moistureChecked.value)
            .then((res:any) => {
                if(!res.success){
                    message.error("保存失败")
                    return
                }
                message.success("保存成功")
                moistureChecked.value.id = res.data;
            });
    }

    return {
        moistureChecked,

        Moisture,

        getMoistureByMpIdAndDate,
        updateMoisture
    }
}